import os
import shutil
import uuid

import requests

url_text_path = "E:\\dataSet\\qrcode_cocodata\\valid\\image.txt"
output_path = "E:\\dataSet\\qrcode_cocodata\\valid\\images\\"

detect_txt_file_dir = "E:\\project\\yolov5-master\\runs\\detect\\exp\\labels"
detect_image_file_dir = "E:\\project\\yolov5-master\\runs\\detect\\exp\\"
image_output_dir = "E:\\project\\yolov5-master\\runs\\detect\\exp\\images\\"


def downloadFromText():
    with open(url_text_path, 'r') as url_file:
        url = url_file.readline()[0:-1]
        while url:
            print(url)
            image_id = str(uuid.uuid1())
            with open(output_path + image_id + ".jpg", 'wb') as image:
                image_byte = requests.get(url).content
                image.write(image_byte)
            url = url_file.readline()[0:-1]


def getDetectImages():
    label_file_list = os.listdir(detect_txt_file_dir)
    for label_file_name in label_file_list:
        images_name = label_file_name.replace(".txt", ".jpg")
        shutil.copy(detect_image_file_dir + images_name, image_output_dir + images_name)


if __name__ == '__main__':
    getDetectImages()
